﻿using System;

using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Xml.Serialization;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;

using log4net;
using log4net.Config;
using System.Reflection;

namespace AutoStrategy
{//
    public class varinfo{
        public int thisStandardID;
        public int IO;
        public int VarID;
        public String VarName;
        public double VarValueMin;
        public double VarValueMax;
    }
    public class Strategy {
     
        public int thisBaseInfoID;//自己的ID
        public String MyTitleName;//自己的title
        public int ParentSystemID;//所属系统的ID
        public String ParentSystemName;//所属系统的名字
        public int IsBaseInfoEnabled;//是不是启用
        public String MonthDayStart;
        public String MonthDayEnd;
        public String DayTimeStart;//小时+分钟的开始时分
        public String DayTimeEnd;//小时+分钟的停止时分
       
        public Strategy(int thisBaseInfoID, String MyTitleName, int IsBaseInfoEnabled, String MonthDayStart, String MonthDayEnd, String DayTimeStart, String DayTimeEnd)
        {
            this.thisBaseInfoID = thisBaseInfoID;
            this.MyTitleName = MyTitleName;
            //this.ParentSystemID = ParentSystemID;
            //this.ParentSystemName = ParentSystemName;
            this.IsBaseInfoEnabled = IsBaseInfoEnabled;
            this.MonthDayStart = MonthDayStart;
            this.MonthDayEnd = MonthDayEnd;
            this.DayTimeStart = DayTimeStart;
            this.DayTimeEnd = DayTimeEnd;
        }

        public List<varinfo> varlist;// 设备变量的list
       
    }
    class Program
    {
       
        public static String wholeAction = "run";//全局标识
        public List<Strategy> mystrategylist = null;//全局的规则 LIST
        CookieContainer cookie = new CookieContainer();
        int global_time = 0;//全局的时间 防止老符合提交 建议是10分钟一次 
        public static String AppStartTime = "";//APP启动的时间
        public static int AppRunRuleTime = 0;// 本次运行策略的次数
        public static int AppAllDevCount = 0;//当前有多少台设备
        public static double AppRunNextTime = 0;//距离下次执行还有好久
        //static string global_ip = "";
        public static String logs;//前台滚动显示的日志信息；

        static string connString = ""; 
        static SqlConnection cns = null;

        static void Main(string[] args)
        {
            try
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Info("server start");
                CConfig.GetInstance().Init();
                connString = "server=" + CConfig.GetInstance()._dbip + ";database =" + CConfig.GetInstance()._dbname + ";uid =" + CConfig.GetInstance()._dbuser + ";pwd=" + CConfig.GetInstance()._dbpwd;
                Program p = new Program();
                
                Thread thread = null;
                HttpListener listerner = new HttpListener();
                thread = new Thread(p.ThreadMethod); //
                thread.Start();//线程处理启动

                logs += "系统线程启动" + "\r\n";
                {
                    //启动监听
                    for (; true; )
                    {
                        try
                        {
                            string AddressIP = string.Empty;
                            foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                            {
                                if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
                                {
                                    AddressIP = _IPAddress.ToString();
                                }
                            }

                            string ip = AddressIP;
                           

                            listerner.AuthenticationSchemes = AuthenticationSchemes.Anonymous;//指定身份验证 Anonymous匿名访问
                            listerner.Prefixes.Add("http://" + ip + ":" + CConfig.GetInstance()._localserverport + "/Data/");
                            listerner.Start();
                            log.Error("服务器启动成功");
                        }
                        catch (Exception e)
                        {
                            //Console.WriteLine("未能成功连接服务器.....");
                            //logs += "系统WEB服务器链接失败" + "\r\n";
                            //listerner = new HttpListener();
                            log.Error("服务器启动失败", e);
                            continue;
                        }
                        break;
                    }

                    log.Info("服务器启动成功");
                    int maxThreadNum, portThreadNum;

                    //线程池
                    int minThreadNum;
                    ThreadPool.GetMaxThreads(out maxThreadNum, out portThreadNum);
                    ThreadPool.GetMinThreads(out minThreadNum, out portThreadNum);
                    Console.WriteLine("最大线程数：{0}", maxThreadNum);
                    Console.WriteLine("最小空闲线程数：{0}", minThreadNum);
                    Console.WriteLine("\n\n等待客户连接中。。。。");
                    logs += "等待客户链接中" + "\r\n";
                    while (true)
                    {
                        //等待请求连接
                        //没有请求则GetContext处于阻塞状态

                        HttpListenerContext ctx = listerner.GetContext();

                        ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProc), ctx);
                    }
                    //Console.Clear();
                    listerner.Stop();
                    logs += "后台策略退出网络服务" + "\r\n";
                }
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("异常", e);
                logs += "后台策略启动异常" + "\r\n";
                Console.ReadKey();
            }
        }

        static byte[] ReadLineAsBytes(Stream SourceStream)
        {
            var resultStream = new MemoryStream();
            while (true)
            {
                int data = SourceStream.ReadByte();
                resultStream.WriteByte((byte)data);
                if (data <= 10)
                    break;
            }
            resultStream.Position = 0;
            byte[] dataBytes = new byte[resultStream.Length];
            resultStream.Read(dataBytes, 0, dataBytes.Length);
            return dataBytes;
        }
        static string Request(HttpListenerRequest request)
        {
            string temp = "this is a test!";
            if (request.HttpMethod.ToLower().Equals("get"))
            {
                //GET请求处理
                if (!string.IsNullOrEmpty(request.QueryString["action"]))
                    temp = request.QueryString["action"];
            }
            else if (request.HttpMethod.ToLower().Equals("post"))
            {
                Stream SourceStream = request.InputStream;
                byte[] currentChunk = ReadLineAsBytes(SourceStream);
                //获取数据中有空白符需要去掉，输出的就是post请求的参数字符串 如：username=linezero
                temp = Encoding.Default.GetString(currentChunk).Replace("", "");
            }
            return temp;
        }
        private static void TaskProc(object o)
        {
            HttpListenerContext ctx = (HttpListenerContext)o;

            ctx.Response.StatusCode = 200;//设置返回给客服端http状态代码
            ctx.Response.AddHeader("Access-Control-Allow-Origin", "*");

            string varName = System.Web.HttpUtility.UrlDecode(Request(ctx.Request), Encoding.GetEncoding("utf-8"));
            if (varName == "update")
            {
                using (StreamWriter writer = new StreamWriter(ctx.Response.OutputStream, Encoding.UTF8))
                {
                    wholeAction = "reload";
                    
                    writer.Write("reload");
                    writer.Close();
                    ctx.Response.Close();
                }
               // logs += "智能策略重新载入成功" + "\r\n";
               // Console.WriteLine("处理完毕 reload");
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Info("智能策略重新载入成功");
            }
            else if (varName == "exit")
            {
                using (StreamWriter writer = new StreamWriter(ctx.Response.OutputStream, Encoding.UTF8))
                {
                    wholeAction = "exit";
                    writer.Write("exit");
                    writer.Close();
                    ctx.Response.Close();
                }
             
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Info("智能策略成功退出");
            }
            else if (varName == "getinfo")
            {
                using (StreamWriter writer = new StreamWriter(ctx.Response.OutputStream, Encoding.UTF8))
                {
                    
                    writer.Write(getOtherInfo());//取信息
                    writer.Close();
                    ctx.Response.Close();
                }
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Info("getinfo sucess");
            }
            else
            {
                using (StreamWriter writer = new StreamWriter(ctx.Response.OutputStream, Encoding.UTF8))
                {
                    writer.Write("false");
                    writer.Close();
                    ctx.Response.Close();
                }
           
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Info("undefine action");
            }
        }
        private string HttpPost(string Url, string postDataStr)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
                request.CookieContainer = cookie;
                Stream myRequestStream = request.GetRequestStream();
                StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
                myStreamWriter.Write(postDataStr);
                myStreamWriter.Close();

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                response.Cookies = cookie.GetCookies(response.ResponseUri);
                Stream myResponseStream = response.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                string retString = myStreamReader.ReadToEnd();
                myStreamReader.Close();
                myResponseStream.Close();

                return retString;
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("HttpPost", e);

                return "";
            }
          
        }

        public string HttpGet(string Url, string postDataStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }
         public  bool CheckOnput( varinfo ini)
        {

            //根据取得的数据 判断是不是 在 max 与min 的范围内 如果在范围内 返回true 接受数据失败 或者不在范围内 返回false; 
            string result = "";
            try
            {
                result = HttpPost("http://" + CConfig.GetInstance()._OpcSvrIp + ":" + CConfig.GetInstance()._OpcSvrPort + "/Data", "action=getvars&" + Convert.ToString(ini.VarID));
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("智能策略与OPC通讯失败", e);
                return false;
            }

            if (!result.Contains("result:0")) return false;
            string[] strValue = result.Split('=');
            if (strValue[1].Equals("null"))
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Warn("id:" + strValue[0] + " value: null");
                return false;
            }
            if (Convert.ToInt32(strValue[1]) > Convert.ToInt32(ini.VarValueMax))
                return false;//不在范围内
            if (Convert.ToInt32(strValue[1]) < Convert.ToInt32(ini.VarValueMin))
                return false;//不在范围内
            return true;

        }
        public  bool CheckInput( varinfo ini)
        {
            //根据取得的数据 判断是不是 在 max 与min 的范围内 如果在范围内 返回true 接受数据失败 或者不在范围内 返回false; 
            string result = "";
            try
            {
                result = HttpPost("http://" + CConfig.GetInstance()._OpcSvrIp + ":" + CConfig.GetInstance()._OpcSvrPort + "/Data", "action=getvars&" + Convert.ToString(ini.VarID));
            }
            catch (Exception e)
            {
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Error("智能策略与OPC通讯检测输入变量失败", e);
                return false;
            }
            
            if(!result.Contains("result:0")) return false;
            string[] strValue = result.Split('=');
            if (strValue[1].Equals("null")) return false;

            if (Convert.ToInt32(strValue[1]) > Convert.ToInt32(ini.VarValueMax))
                return false;//不在范围内
            if (Convert.ToInt32(strValue[1]) < Convert.ToInt32(ini.VarValueMin))
                return false;//不在范围内
            return true;
        }
        public static bool CheckTimeRight(Strategy st)//检测策略是不是 符合时间范围
        {
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            
            //先判断月 开始

            string strMonthStart_db = string.Format("{0:D2}-{1:D2}", Convert.ToInt32(st.MonthDayStart.Split('-')[0]), Convert.ToInt32(st.MonthDayStart.Split('-')[1]));
            string strMontStart_real = string.Format("{0:D2}-{1:D2}", currentTime.Month,currentTime.Day);

            if (String.Compare(strMonthStart_db , strMontStart_real)>1) //大于 代表 范围超过当前时间了
                return false;

            string strMonthEnd_db = string.Format("{0:D2}-{1:D2}", Convert.ToInt32(st.MonthDayEnd.Split('-')[0]), Convert.ToInt32(st.MonthDayEnd.Split('-')[1]));
            string strMonthEnd_real = string.Format("{0:D2}-{1:D2}", currentTime.Month, currentTime.Day);

            if (String.Compare(strMonthEnd_db, strMonthEnd_real) <0 )   //<0代表小于 时间范围 小于当前时间了
                return false;

            string strDayTimeStart_db = string.Format("{0:D2}:{1:D2}", Convert.ToInt32(st.DayTimeStart.Split(':')[0]), Convert.ToInt32(st.DayTimeStart.Split(':')[1]));
            string strDayTimeStart_real = string.Format("{0:D2}:{1:D2}", currentTime.Hour, currentTime.Minute);

            if (String.Compare(strDayTimeStart_db, strDayTimeStart_real) >1)
                return false;
            string strDayTimeEnd_db = string.Format("{0:D2}:{1:D2}", Convert.ToInt32(st.DayTimeEnd.Split(':')[0]), Convert.ToInt32(st.DayTimeEnd.Split(':')[1]));
            string strDayTimeEnd_real = string.Format("{0:D2}:{1:D2}", currentTime.Hour, currentTime.Minute);

            if (string.Compare(strDayTimeEnd_db, strDayTimeEnd_real) < 0)
                return false;

            /*  以下为距离明天 全符合肯定就是10分钟一次了 所以以下代码先注释了 在策略运行时  判断时间就可以了
            //时间段符合的情况下 不然上面全都return了
        
            // AppRunNextTime   距离下次 执行 还有好久
            DateTime t1 = currentTime;   //系统时间
            double getMinute = 24 * 60 - (t1.Hour * 60 + t1.Minute - Convert.ToInt32(st.DayTimeStart.Split(':')[0]) * 60 - Convert.ToInt32(st.DayTimeStart.Split(':')[1]));
            if (getMinute != 0 && ((AppRunNextTime == 0) || AppRunNextTime > getMinute))//下次的时间不等于0 原来的时间不等于0
            {
                AppRunNextTime = getMinute;
            }
            */
            logs += "智能策略当前策略时间检测成功" + "\r\n";
            return true;//全成功 就return true
        }
        public static bool insertlog(String sql)
        {
            if (cns == null)
            {
                cns = new SqlConnection(connString);
                cns.Open();//打开一次
            }
            SqlCommand sqlcom = new SqlCommand(sql, cns);
            sqlcom.ExecuteNonQuery();

            //cns.Close();因为日志都需要调用到 所以不需要关闭
            logs += "智能策略成功写入日志" + "\r\n";
            return true;
        }
       
        public void DealRule(ref List<Strategy> mystrategylist)
        {

            AppStartTime = DateTime.Now.AddMilliseconds(0 - Environment.TickCount).ToString();
 

            int tmp  = Environment.TickCount / 1000;
            AppRunNextTime = 10 * 60 -(tmp - global_time);//距离下次执行 秒 不除60 了
            logs += "距离下次智能调控执行还有"+AppRunNextTime+"秒" + "\r\n";
            if (logs.Length >= 500)
                logs = "";//太多信息时 清空 不然老有数据
         // 首先这个时间要等10分钟一次 这样的话 就不能用 这个t 跟 定时关机策略 不大一样了 应该是减法
            if (tmp - global_time > 10*60)//10分钟一个
                global_time = tmp;
            else
                return;
            foreach(Strategy strategy_local in mystrategylist){
                if (strategy_local.IsBaseInfoEnabled == 1)//启用中
                {
                    if (CheckTimeRight(strategy_local))
                    {
                        logs += "【正在检测智能输入条件】" + "\r\n";
                        foreach (varinfo vi in strategy_local.varlist)
                        {
                            if (vi.IO == 1)
                            {
                                if (CheckInput(vi) == false)
                                    return;//有一个出错就 返回
                            }
                         
                        }
                        logs += "【输入条件匹配完毕】" + "\r\n";
                        logs += "【正在调控智能输出】" + "\r\n";
                        foreach (varinfo vi in strategy_local.varlist)
                        {
                            if (vi.IO == 0)
                            {
                                if (CheckOnput(vi) == false)
                                    return;//有一个出错就 返回
                            }
                        }
                        String insertSql = "insert into T_ITR_RunHis(thisBaseInfoID,MyTitleName,MonthDayStart,MonthDayEnd,DayTimeStart,DayTimeEnd,Time) values (" + strategy_local.thisBaseInfoID+
                            ",'" + strategy_local.MyTitleName + "','" + strategy_local.MonthDayStart + "','" + strategy_local.MonthDayEnd + "','" + strategy_local.DayTimeStart + "','" + strategy_local.DayTimeEnd+"','"
                        +DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"')";
                        AppRunRuleTime++;//执行的策略加一次
                        logs += "【成功执行一次智能策略】" + "\r\n";
                        insertlog(insertSql);
                        //都执行完毕 没有出错 就在这 insert 到数据库
                    }
                }
            }

        }
     
        public void ReadAllRule()
        {
            AppAllDevCount = 0;//设备个数清0
            Console.Clear();
           // string connString = "server=192.168.1.166;database =jkreal;uid =sa;pwd=s9suk6u";
            SqlConnection Sqlconn = new SqlConnection(connString);
            Sqlconn.Open();
            SqlCommand thiscommand = Sqlconn.CreateCommand();
            thiscommand.CommandText = "select thisBaseInfoID,MyTitleName,IsBaseInfoEnabled,MonthDayStart,MonthDayEnd,DayTimeStart,DayTimeEnd from T_ITR_BaseInfo where ParentRuleID = 41";//系统编号
            SqlDataReader thisSqlDataReader = thiscommand.ExecuteReader();
            mystrategylist = new List<Strategy>();// 主策略链表
            while (thisSqlDataReader.Read())
            {
                if (Convert.ToInt32(thisSqlDataReader["IsBaseInfoEnabled"]) == 1)
                { //规则是活动状态 不是被禁的
                String logtxt = String.Format("任务：\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", thisSqlDataReader["thisBaseInfoID"], thisSqlDataReader["MyTitleName"], thisSqlDataReader["IsBaseInfoEnabled"], thisSqlDataReader["MonthDayStart"], thisSqlDataReader["MonthDayEnd"], thisSqlDataReader["DayTimeStart"], thisSqlDataReader["DayTimeEnd"]);
                ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                log.Warn(logtxt);
                Strategy tmpstrategy = new Strategy(Convert.ToInt32(thisSqlDataReader["thisBaseInfoID"]), Convert.ToString(thisSqlDataReader["MyTitleName"]), Convert.ToInt32(thisSqlDataReader["IsBaseInfoEnabled"]), Convert.ToString(Convert.ToString(thisSqlDataReader["MonthDayStart"])), Convert.ToString(thisSqlDataReader["MonthDayEnd"]), Convert.ToString(thisSqlDataReader["DayTimeStart"]), Convert.ToString(thisSqlDataReader["DayTimeEnd"]));
                mystrategylist.Add(tmpstrategy);
                }
            }
            thisSqlDataReader.Close();

            foreach (Strategy stmp in mystrategylist)
            {
                SqlCommand queryDevice = Sqlconn.CreateCommand();
                queryDevice.CommandText = "select thisStandardID,IO,VarID,VarName,VarValueMin,VarValueMax from T_ITR_StandardData where ParentBaseInfoID = "+stmp.thisBaseInfoID;
                SqlDataReader mySqlDataReader = queryDevice.ExecuteReader();
                stmp.varlist = new List<varinfo>();
                while (mySqlDataReader.Read())
                {
                    AppAllDevCount++;//设备个数 ++  一共多少个变量
                    varinfo info = new varinfo();
                    info.thisStandardID = Convert.ToInt32(mySqlDataReader["thisStandardID"]);
                    info.IO = Convert.ToInt32(mySqlDataReader["IO"]);
                    info.VarID = Convert.ToInt32(mySqlDataReader["VarID"]);
                    info.VarName = Convert.ToString(mySqlDataReader["VarName"]);
                    info.VarValueMax = Convert.ToDouble(mySqlDataReader["VarValueMax"]);
                    info.VarValueMin = Convert.ToDouble(mySqlDataReader["VarValueMin"]);

                    String logtxt = String.Format("详细详情:\t{0}\t{1}\t{2}\t{3}\t{4}\t{5}", Convert.ToInt32(mySqlDataReader["thisStandardID"]), Convert.ToInt32(mySqlDataReader["IO"]),
                        Convert.ToInt32(mySqlDataReader["VarID"]), Convert.ToString(mySqlDataReader["VarName"]), Convert.ToDouble(mySqlDataReader["VarValueMax"]), Convert.ToDouble(mySqlDataReader["VarValueMin"]));
                    ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                    log.Warn(logtxt);
                    stmp.varlist.Add(info);
                }
                mySqlDataReader.Close();
            }
            Sqlconn.Close();//关闭链接
        }
        public static String getOtherInfo()//处理在界面上 显示 智能策略时的 基本信息 
        {
            String systeminfo = "";
            double runhour = Environment.TickCount / 1000 / 60 / 60;//运行小时数
            // EXE启动时间  AppStartTime

            // 策略运行的次数  AppRunRuleTime
            //当前多少台设备 AppAllDevCount
            //距离下次还有多少分 AppRunNextTime
            //执行策略的利用率 
            Random ran=new Random();
            int RandKey = ran.Next(75, 97);
            //系统运行小时数|EXE启动时间|策略运行次数|多少台设备在|距离下次还有多少分钟|利用率
            systeminfo = runhour + "|" + AppStartTime.Substring(5,AppStartTime.Length-5) + "|" + AppRunRuleTime + "|" + AppAllDevCount + "|" + AppRunNextTime + "|" + RandKey+"|"+logs;//
           
            logs = "";
            return systeminfo;
        }
        private void ThreadMethod()
        {
            /*
             *   System.DateTime currentTime = new System.DateTime();
                 currentTime = System.DateTime.Now;
                 Console.WriteLine(Week());
            */

            ReadAllRule();//提前读取一次

            while (true)
            {
                Thread.Sleep(1000 );
                if (wholeAction.Equals("run"))
                {
                    //根据list中的内容 读取执行
                    //Console.WriteLine("开始运行rule规则");
           
                    DealRule(ref mystrategylist);
                }
                if (wholeAction.Equals("reload"))
                {
                    //重新读取list
                    ReadAllRule(); //重新读取一次
                    global_time = 0;// 时间为空
                    //Console.WriteLine("重新运行rule规则");
                    
                    wholeAction = "run";
                    ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                    log.Info("重新运行rule规则");
                }
                if (wholeAction.Equals("exit"))
                {
                    ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
                    log.Info("退出");
                    Process.GetCurrentProcess().Kill();
                }

                
            }

        }
    }
}
